<template>
	<el-container>
		<el-header>
		 <el-row :gutter="20">
				<el-col :span="4">

					<el-select v-model="select.uid" placeholder="请选择用户" filterable>
						<el-option  label="全部" value="-1">
						</el-option>
						<el-option v-for="(item,index) in users" :key="index" :label="item.nickname" :value="item.id">
						</el-option>
					</el-select>
				</el-col>
				<el-col :span="4">
					 <el-button type="primary" @click="search">查找</el-button>
				</el-col>
			</el-row>
		</el-header>
		<el-main>
			<el-table :data="list" style="width: 100%">
				<el-table-column label="用户">
					<template slot-scope="scope">
						<div v-if="scope.row.user">
							{{scope.row.user.nickname}}
						</div>
					</template>
				</el-table-column>
				<el-table-column label="内容" prop="content">
				</el-table-column>

		</el-table-column>
				<el-table-column label="状态">
          <template slot-scope="scope">
          	{{state[scope.row.state]}}
          </template>
				</el-table-column>

      <!--  <el-table-column label="图片">
        	<template slot-scope="scope">
        		<el-image style="width: 50px; height: 50px" :src="scope.row.image"></el-image>
        	</template>
        </el-table-column>
        <el-table-column label="二维码">
        	<template slot-scope="scope" >
        		<el-image style="width: 50px; height: 50px" :src="scope.row.qrcode"></el-image>
        	</template>
        </el-table-column> -->

				<el-table-column label="日期" prop="created_at">
				</el-table-column>
			</el-table>



		</el-main>
		<el-footer>
			<el-pagination background layout="prev, pager, next" :page-size="search_form.num" :total="total"
				@current-change="current_change">
			</el-pagination>
		</el-footer>
	</el-container>
</template>

<script>
	export default {
		data() {
			return {
				search_form: {
					table: "turntable_logs",
					page: 1,
					num: 5,
					where: null,
					orderBy: "id",
					asdes: "asc"
				},
				select: {
					uid: "-1",
				},
				type: ["鸡生蛋", "用户领取鸡蛋"],
				state: ["未领取", "已领取"],
				list: [],
				total: 0,
				users: []
			}
		},
		mounted() {
			this.get_data()
			this.get_user()
		},
		methods: {
			get_user() {
				let data = {
					"table": "users",
					"select": ["id", "nickname"]
				}
				this.$model.post("/cms/table/get_all",data).then(res=>{
					if(res.code==200){
						this.users=res.data
					}
				})
			},
			get_data() {
				this.$model.post("/cms/table/get", this.search_form).then(res => {
					if (res.code == 200) {
						this.list = res.data.data
						this.total = res.data.total
					}
				})
			},
			search() {
				this.search_form.where = []
				let where = []
				for (let i in this.select) {
					console.log(this.select[i])
					if (this.select[i] != "-1") {
						where = [i, "=", this.select[i]]
						this.search_form.where.push(where)
					}
				}
				this.search_form.page = 1
				this.get_data()
			},
			current_change(e) {
				this.search_form.page = e
				this.get_data()
			}
		}
	}
</script>

<style>
</style>
